<?php
/**
 * 后台菜单管理控制器
 * @author maniac
 */
namespace app\shop\controller;

use app\facade\AdminMenus AS AdminMenusFacade;

class AdminMenus extends Base
{
    /**
     * 菜单管理首页
     */
    public function index()
    {
        $menus = $this->menus();
        foreach ($menus as $k => $v) {
            $menus[$k]['sub_ids'] = implode(',', get_sub_ids('app\common\model\AdminMenus', $v['id']));
        }
        return $this->fetch('', [
            'menus' => $menus,
        ]);
    }
    
    /**
     * 添加/编辑附加
     * @param array $info 信息
     */
    public function addAttach($info)
    {
        $pid = input('param.pid/d', 0);
        $menus = $this->menus();
        $this->assign('pid', $pid);
        $this->assign('menus', $menus);
    }
    
    /**
     * 获取所有菜单
     */
    private function menus()
    {
        $menus = AdminMenusFacade::adminMenus();
        $menus = recursion_one_array($menus);
        return $menus;
    }
}
